import moment from "moment";

export default {
    data() {
        return {
            time: [],
            row: {},
            printing: false,
            name: 'mixin',
            tableData: [],
            searchForm: {},
            loading: false,
            page: {
                pageSize: 10, // 每页的数量
                total: 0, // 总数
                currentPage: 1 // 当前页
            },
            dialogShow: false,
            formShow: true,
            selection: [],
        }
    },
    created() {
        console.log('mixin...', this.name);
    },
    mounted() {
        this.init()
    },
    methods: {
        // 回调
        callback(res) {
            this.loading = false
            if (res.status === 200) {
                this.$message.success(res.message)
                this.closeMode()
                this.init()
            } else {
                this.$message.error(res.message)
            }
        },
        //关闭弹框
        closeMode() {
            let form = this.$refs['ruleForm']
            if (form) {
                form.resetFields();
            }
            this.dialogShow = false
        },
        currentChange(page) { // 改变页码时
            this.page.currentPage = page
            this.init()
        },
        //重置
        reset() {
            this.searchForm = {}
            this.time = []
        },
        handleSelectionChange(val) {
            this.selection = val
        },
        momentF(v) {
            return moment(v).format("YYYY-MM-DD HH:mm")
        },
        momentSecondToF(s) {
            if (!s) return
            moment.updateLocale('en', {
                relativeTime: {
                    future: "in %s",
                    past: "%s 前",
                    s: '几秒',
                    ss: '%d 秒',
                    m: "一分钟",
                    mm: "%d 分钟",
                    h: "一小时",
                    hh: "%d 小时",
                    d: "一天",
                    dd: "%d 天",
                    M: "一个月",
                    MM: "%d 月",
                    y: "一年",
                    yy: "%d 年"
                }
            });
            let d = moment().millisecond(s)
            return d.toNow(moment(), true)
        }
    }
}